package ttl;
import java.io.IOException;  
import java.util.HashMap;
import java.util.Map;
  
import com.rabbitmq.client.Channel;  
import com.rabbitmq.client.Connection;  
import com.rabbitmq.client.ConnectionFactory;  

public class QuereMsgTTL {
	 private final static String QUEUE_NAME = "TQ-10S";  
	 private final static String HOST = "10.20.53.25";  
	/**
	 * @param args
	 * @throws IOException 
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws IOException, InterruptedException {
		 ConnectionFactory factory = new ConnectionFactory();  
		 	factory.setHost(HOST);
	        Connection connection = factory.newConnection();  
	        Channel channel = connection.createChannel();  
	        
	        Map<String, Object> args1 = new HashMap<String, Object>();
	        args1.put("x-message-ttl", 10000);//This value must same as the value define in Query.
	        
	        channel.queueDeclare(QUEUE_NAME, false, false, false, args1);  
	        for(int index=0;index<10; index++){
		        String message = "Msg info : "+index;  
		        channel.basicPublish("", QUEUE_NAME, null, message.getBytes());  
		        System.out.println(HOST +" [x] Sent '" + message + "'");
		        Thread.sleep(5000);
	        }
	  
	        channel.close();  
	        connection.close();  

	}

}
